package com.annocation;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class DemoTest002 {
    public static void main(String args[]) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
        Class clazz=Student.class;
        Student student= (Student) clazz.newInstance();
        student.setAge(10);
        Constructor constructor= clazz.getDeclaredConstructor(String.class,String.class,int.class);
        Student student1= (Student) constructor.newInstance("1001","高山青",26);
        System.out.println(student.getAge());
        System.out.println(student1.getAge());
        Student student2 = (Student) clazz.newInstance();
        Method method = clazz.getDeclaredMethod("setStudentName", String.class);
         method.invoke(student2,"青青");
         System.out.println(student2.getStudentName());
         Student student4=(Student) clazz.newInstance();
        Field field = clazz.getDeclaredField("age");
        field.setAccessible(true);
        field.set(student4,1111);
        System.out.println(student4.getAge()+" "+field.get(student4));


    }
}
